/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.service;

import com.ivanbiz.dao.GLAccountDAO;
import com.ivanbiz.dao.impl.GLAccountDAOImpl;
import com.ivanbiz.model.GLAccount;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Comboitem;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Window;

/**
 *
 * @author IW20149X
 */
public class LaporanKeuntunganKrediturService extends SelectorComposer<Component> {

    GLAccountDAO gLAccountDAO;
    @Wire
    Combobox listAccount;
    @Wire
    Datebox dari;
    @Wire
    Datebox sampai;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        gLAccountDAO = new GLAccountDAOImpl();
        loadAccount();
    }

    @Listen("onClick=#lihat;")
    public void lihat() {
        GLAccount gLAccount = listAccount.getSelectedItem().getValue();
        Map map = new HashMap();
        map.put("gLAccount", gLAccount);
        map.put("dari", dari.getValue());
        map.put("sampai", sampai.getValue());
        Window win = (Window) Executions.createComponents("/laporanKeuntunganKrediturView.zul", null, map);
        win.doModal();
    }

    private void loadAccount() {
        try {
            List<GLAccount> loadGLAccount = gLAccountDAO.getDataByEquals(GLAccount.class, "groupACC", "Kreditur");
            for (GLAccount gLAccount : loadGLAccount) {
                Comboitem item = new Comboitem();
                item.setValue(gLAccount);
                item.setLabel(gLAccount.getNameGL() + " A/C No. " + gLAccount.getNoGL());
                listAccount.appendChild(item);
            }
        } catch (Exception ex) {
            Logger.getLogger(LaporanKeuntunganKrediturService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
